package cn.chenhuanming.chuanzhi.util.entity;// default package

import cn.chenhuanming.chuanzhi.util.entity.converter.LocalDateTimeConverter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;

/**
 * Vote entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "vote", catalog = "website")
@DynamicInsert
@DynamicUpdate
public class Vote implements java.io.Serializable {

	// Fields

	private String id;
	private Staff staff;
	private String title;
	private String content;
	private LocalDateTime createDate;
	private Short status;
	private Set<VoteOption> voteOptions = new HashSet<VoteOption>(0);

	// Constructors

	/** default constructor */
	public Vote() {
	}

	/** minimal constructor */
	public Vote(String id, Staff staff, String title) {
		this.id = id;
		this.staff = staff;
		this.title = title;
	}

	/** full constructor */
	public Vote(String id, Staff staff, String title, String content,
				LocalDateTime createDate, Short status, Set<VoteOption> voteOptions) {
		this.id = id;
		this.staff = staff;
		this.title = title;
		this.content = content;
		this.createDate = createDate;
		this.status = status;
		this.voteOptions = voteOptions;
	}

	// Property accessors
	@Id
	@GeneratedValue(generator = "UUID")
	@GenericGenerator(
			name = "UUID",
			strategy = "org.hibernate.id.UUIDGenerator"
	)
	@Column(name = "id", unique = true, nullable = false, length = 36)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "creator", nullable = false)
	public Staff getStaff() {
		return this.staff;
	}

	public void setStaff(Staff staff) {
		this.staff = staff;
	}

	@Column(name = "title", nullable = false)
	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "content")
	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Convert(converter = LocalDateTimeConverter.class)
	@Column(name = "create_date", length = 19)
	public LocalDateTime getCreateDate() {
		return this.createDate;
	}

	public void setCreateDate(LocalDateTime createDate) {
		this.createDate = createDate;
	}

	@Column(name = "status")
	public Short getStatus() {
		return this.status;
	}

	public void setStatus(Short status) {
		this.status = status;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "vote")
	public Set<VoteOption> getVoteOptions() {
		return this.voteOptions;
	}

	public void setVoteOptions(Set<VoteOption> voteOptions) {
		this.voteOptions = voteOptions;
	}

}